﻿using AutoMapper;
using MediatR;
using Traceability.App.API.Application.Command.Supplier;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.Supplier
{
    public class GetSupplierHandler : IRequestHandler<GetSupplierCommand, APIResult<SupplierModel>>
    {
        private readonly IBaseRepository<SupplierModel> supplierRepo;

        public GetSupplierHandler(IBaseRepository<SupplierModel> supplierRepo)
        {
            this.supplierRepo = supplierRepo;
        }
        public Task<APIResult<SupplierModel>> Handle(GetSupplierCommand request, CancellationToken cancellationToken)
        {
            APIResult<SupplierModel> result = new APIResult<SupplierModel>();
            var res = supplierRepo.GetAll().FirstOrDefault(x => x.Batch == request.Batch && x.SupplierType == request.SupplierType);
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
